import random

from base.base_page import BasePage


class UserPage(BasePage):

    # 头像
    def user_avatar_btn(self):
        return self.by_id(self.HW_ENV + 'update_user_avatar').click()

    def back_btn(self):
        return self.by_id(self.HW_ENV + 'navibar_back').click()

    # 昵称
    def nickname_btn(self):
        return self.by_id(self.HW_ENV + 'btn_change_nick_name').click()

    # 修改昵称输入框
    def edit_nickname(self):
        return self.by_id(self.HW_ENV + 'edit_nick_name')

    # 修改昵称-确定
    def save_btn(self):
        return self.by_id(self.HW_ENV + 'btn_confirm').click()

    def do_edit_nickname(self):
        """
        修改随机昵称
        """
        words = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
        name = ''.join(random.choice(words) for x in range(4))
        self.nickname_btn()
        print('修改昵称：' + name)
        self.edit_nickname().send_keys(name)
        self.save_btn()

